import Vue from "vue";
import clone from "ramda/src/clone";

let uid = 0;
export function staticComputer(init) {
    const state = Vue.observable({ toolMan: false });
    const str = "__static-" + uid++;
    const map = new Map();
    return {
        get() {
            const key = this._uid + str;
            // eslint-disable-next-line
            if (!map.has(key)) {
                map.set(key, clone(init));
            }
            // eslint-disable-next-line
            !state.toolMan;
            return map.get(key);
        },
        set(val) {
            const key = this._uid + str;
            map.set(key, val);
            state.toolMan = !state.toolMan;
        },
    };
}
